import { getToken } from '@/utils/auth'

const getDefaultState = () => { return { token: getToken(), name: '', avatar: '', roleId: 0,roleName: '',Nodes:'',userId:'' } }
const state = getDefaultState()
const mutations = {
  resetState: (state) => { Object.assign(state, getDefaultState()) },
  setToken: (state, token) => { state.token = token },
  setName: (state, name) => { state.name = name },
  setAvater: (state, avatar) => { state.avatar = avatar },
  setRoleId: (state, roleId) => { state.roleId = roleId },
  setRoleName: (state, roleName) => { state.roleName = roleName },
  setNodes: (state, Nodes) => { state.Nodes = Nodes },
  setUserId: (state, userId) => { state.userId = userId },
  setForm: (state, form) => { state.form = form }
}

const actions = {
  state({ commit }, stateData) {
    commit(stateData.keyName, stateData.value)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

